<?php
// On établis la connection
require_once ('../../connexion.php');

// les variables

$login=$_POST['loginInscri'];
$mdp=hash("sha256", $_POST['passwordInscri']);
$civil=$_POST['civilite'];
$nom=$_POST['nom'];
$prenom=$_POST['prenom'];
$tel=$_POST['telephone'];
$ville=$_POST['ville'];
$cp=$_POST['cp'];
$adr=$_POST['adresse'];
$mail=$_POST['mail'];

if (isset($_POST['newsLetter'])){
	$news="oui";
}
else{
	$news="non";
}


echo "<h1>Inscription</h1><div class='cadreContenu'>";
if ($_POST['g-recaptcha-response']!=""){
	// Insertion des données

		// On envois la requète (insert )
	try{
		$sqlInsert = 'INSERT INTO membres VALUES(:login, :mdp, :civil, :nom, :prenom, :tel, :ville, :cp, :adr, :mail, :client, :news)';
		$insert = $connection->prepare($sqlInsert, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
		$insert->execute(array(':login' => $login, ':mdp' => $mdp, ':civil' => $civil, ':nom' => $nom, ':prenom' => $prenom, ':tel' => $tel, ':ville' => $ville, ':cp' => $cp, ':adr' => $adr, ':mail' => $mail, ':client' => 'client', ':news' => $news));
		
		
		// on test le succes
		if ($insert==true){
			echo "<h3>Inscription réussie !</h3>";
		}		
	
		
	}catch(Exception $e){
		echo "<h3 class='error'>Une erreur est survenue lors de l'inscription</h3>";
	}
}else{
	session_start();
	$_SESSION['inputs']=$_POST;
	echo "<h3 class='error'>Vous avez oublié de valider le captcha ! </h3>";
}
echo "</div>";
?>